/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.ui.components;

import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import org.bff.slimserver.musicobjects.SlimGenre;

/**
 *
 * @author bfindeisen
 */
public class GenreComboBox extends JComboBox {

    private DefaultComboBoxModel genreModel;

    public GenreComboBox() {
        genreModel = new DefaultComboBoxModel();
       listGenres();
    }

    private void listGenres() {
        genreModel.removeAllElements();
        try {
            genreModel.addElement(new String("All"));
            List<SlimGenre> genreList = new ArrayList<SlimGenre>(JukeboxProperties.getInstance().getDatabase().getGenres());
            for (SlimGenre genre : genreList) {
                genreModel.addElement(genre);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        setModel(genreModel);
    }
    
    public SlimGenre getSelectedGenre() {
        if(getSelectedIndex() == 0) {
            return null;
        }
        
        return (SlimGenre) getModel().getSelectedItem();
    }
}
